﻿
package com.ostrich.project.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.base.service.BaseService;
import com.ostrich.manpower.bean.TostHrBaseinfo;
import com.ostrich.manpower.bean.TostHrDepartinfo;
import com.ostrich.manpower.bean.TostHrPostinfo;
import com.ostrich.manpower.service.impl.TostHrBaseinfoService;
import com.ostrich.manpower.service.impl.TostHrDepartinfoService;
import com.ostrich.manpower.service.impl.TostHrPostinfoService;
import com.ostrich.project.bean.TostPjCostitem;
import com.ostrich.project.bean.TostPjGeneraltable;
import com.ostrich.project.service.TostPjGeneraltableDao;
/**
 * @author wangyinan
 * @brief    模块功能简单描述
 * @details  模块功能详细描述
 */
@Service("tostPjGeneraltableService")
public class TostPjGeneraltableService<T> extends BaseService<T> {
	private final static Logger log= Logger.getLogger(TostPjGeneraltableService.class);

	@Autowired
    private TostPjGeneraltableDao<T> dao;
	@Autowired(required=false)
	private TostHrBaseinfoService<TostHrBaseinfo> tosthrbaseinfoservice;
	@Autowired(required=false)
	private TostHrDepartinfoService<TostHrDepartinfo> tosthrdepartinfoservice;
	@Autowired(required=false)
	private TostHrPostinfoService<TostHrPostinfo> tosthrpostinfoservice;
	
	public TostPjGeneraltableDao<T> getDao() {
		return dao;
	}
	
	public void addGeneral(TostPjGeneraltable tpjgl,String nickname) throws Exception{
		
		
		String caratetime=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		
		float scale=tpjgl.getPgeScale();//项目系统系数
		float jobtime=tpjgl.getPgeJobtime();//项目服务时间
		float basewage=tpjgl.getPgeBasewage();//非工资支出费用基数
		float wagepayment=scale*jobtime*basewage;
		
		tpjgl.setPgeWagepayment(wagepayment);
		
		int hrid=tpjgl.getHrId();
		
		TostHrBaseinfo thb=tosthrbaseinfoservice.queryById(hrid);
		String hdpid = null;
		//for(TostHrBaseinfo thb:list){
			hdpid=thb.getHrDepart();
			tpjgl.setHrName(thb.getHrName());
			tpjgl.setHdpId(hdpid);//部门id
		//}
		
		int hpoid=tpjgl.getHpoId();
		TostHrPostinfo thp=tosthrpostinfoservice.queryById(hpoid);
		tpjgl.setPgeJobs(thp.getHpoName());
		
		TostHrDepartinfo thd=tosthrdepartinfoservice.queryById(hdpid);
		tpjgl.setHdpName(thd.getHdpName());
		
		tpjgl.setCreatetime(caratetime);
		tpjgl.setPerson(nickname);
		
		if(tpjgl.getId()!=null && tpjgl.getId()>0)
			this.update((T) tpjgl);
		else
			this.add((T) tpjgl);
		
	}
	public java.util.List<TostPjGeneraltable> queryGen(){
		java.util.List<TostPjGeneraltable> list=new ArrayList<TostPjGeneraltable>();
		list=dao.queryGen();
		return list;
	}
	
	
	public void deleteByPctId(Integer pctId) throws Exception{
		 dao.deleteByPctId(pctId);
	}
	
	public Map<String,Object> queryByHrid(Integer hrId){
		return dao.queryByHrid(hrId);
	}
}
